home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
-
- Real World Apple Guide
- by Jesse Feiler
-
- Copyright © 1995 Philmont Software Mill. All Rights Reserved.
-
- ISBN 1-55851-429-5
-
- To order additional copies, call M&T Books, 1-800-488-5233
-
- For updates, check the bulletin board in the Philmont Software Mill
- area on eWorld (shortcut "Philmont" or path "Computer Center : Straight to the
- Source : Philmont Software Mill").
-
- Send bug reports to ePhilmont@eWorld.com, or post to the bulletin
- board in the Philmont Software Mill area on eWorld.
-
- **********************************************************************/
-
- #include "contextCheck.h"
-
- enum {
- compareSignatureOnly = 0,
- compareMajorRevOnly = 1,
- compareMajorAndMinorRev = 2,
- compareAllRevs = 3
- };
-
- /* prototypes */
- Boolean VersionAppRunning (short whichCompare, OSType signature, UInt8 majorRev, UInt8 minorRev, UInt8 bugRev);
- OSErr SetContextResult(void* theData, Size theSize, Ptr* outMessage, Size* outSize);
-
- pascal OSErr
- main(contextCheckData* msg, Size inSize, void* outMessage,Size* outSize, Handle ignoreMe )
- {
- OSErr err = errAECorruptData; // the default return value of the operation
- Boolean result = FALSE; // the default return value of the context check
-
- result = VersionAppRunning (msg->whichCompare, msg->signature, msg->majorRev, msg->minorRev, msg->bugRev);
-
- err = SetContextResult(&result, sizeof(Boolean), outMessage, outSize);
-
- return(err);
- }
-
-
- // Package the result for Apple Guide
- OSErr SetContextResult(void* theData, Size theSize, Ptr* outMessage, Size* outSize)
- {
- Ptr p;
-
- if (p = NewPtr(theSize))
- {
- BlockMove(theData, p, theSize);
-
- *outSize = theSize;
- *outMessage = p;
-
- return(noErr);
- }
- else
- return(MemError()); //A reasonable assumption--if we cannot allocate the
- //pointer for the result, we're out of memory.
- }
-
- Boolean VersionAppRunning (short whichCompare, OSType signature, UInt8 majorRev, UInt8 minorRev, UInt8 bugRev)
- {
- Boolean result = FALSE;
- ProcessSerialNumber PSN;
- ProcessInfoRec info;
- OSErr err;
- Str31 aProcessName;
- FSSpec aProcessAppSpec;
-
- PSN.highLongOfPSN = 0;
- PSN.lowLongOfPSN = kNoProcess;
- info.processInfoLength = sizeof(ProcessInfoRec);
- info.processName = aProcessName;
- info.processAppSpec = &aProcessAppSpec;
-
- while (GetNextProcess(&PSN) == noErr)
- {
- if(GetProcessInformation(&PSN, &info) == noErr)
- {
- if(info.processSignature == signature)
- {
- switch (whichCompare)
- {
- case compareSignatureOnly:
- result = TRUE;
- break;
-
- default:
- {
- short appResource = FSpOpenResFile (&aProcessAppSpec, fsRdPerm);
- short myResError = ResError();
- if (myResError == noErr)
- {
- NumVersion theVersion;
- VersRecHndl aVersRecHndl = (VersRecHndl)GetResource ('vers', 1);
- if (aVersRecHndl)
- {
- MoveHHi ((Handle)aVersRecHndl);
- HLock ((Handle)aVersRecHndl);
- theVersion = ((**aVersRecHndl).numericVersion);
- HUnlock ((Handle)aVersRecHndl);
- };
- CloseResFile (appResource);
-
- switch (whichCompare)
- {
- case compareMajorRevOnly:
- {
- result = (majorRev == theVersion.majorRev);
- break;
- };
-
- case compareMajorAndMinorRev:
- {
- result = (majorRev == theVersion.majorRev)
- && (minorRev == theVersion.minorAndBugRev >> 4);
- break;
- };
-
- case compareAllRevs:
- {
- UInt8 versionComparer = 0;
- versionComparer = (minorRev << 4) + bugRev;
- result = (majorRev == theVersion.majorRev)
- && (versionComparer == theVersion.minorAndBugRev);
- break;
- };
- };
- };
- break; // out of default case
- };
- };//switch statement
- break; //to escape the while loop
- }; //if we found the app
- }; // if we got the process info
- }; //while
-
- return result;
- }
-
-